<!DOCTYPE html><html><head><meta charset="utf-8"><style>body {
  width: 45em;
  border: 1px solid #ddd;
  outline: 1300px solid #fff;
  margin: 16px auto;
}

body .markdown-body
{
  padding: 30px;
}

@font-face {
  font-family: fontawesome-mini;
  src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAzUABAAAAAAFNgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABbAAAABwAAAAcZMzaOEdERUYAAAGIAAAAHQAAACAAOQAET1MvMgAAAagAAAA+AAAAYHqhde9jbWFwAAAB6AAAAFIAAAFa4azkLWN2dCAAAAI8AAAAKAAAACgFgwioZnBnbQAAAmQAAAGxAAACZVO0L6dnYXNwAAAEGAAAAAgAAAAIAAAAEGdseWYAAAQgAAAFDgAACMz7eroHaGVhZAAACTAAAAAwAAAANgWEOEloaGVhAAAJYAAAAB0AAAAkDGEGa2htdHgAAAmAAAAAEwAAADBEgAAQbG9jYQAACZQAAAAaAAAAGgsICJBtYXhwAAAJsAAAACAAAAAgASgBD25hbWUAAAnQAAACZwAABOD4no+3cG9zdAAADDgAAABsAAAAmF+yXM9wcmVwAAAMpAAAAC4AAAAusPIrFAAAAAEAAAAAyYlvMQAAAADLVHQgAAAAAM/u9uZ4nGNgZGBg4ANiCQYQYGJgBEJuIGYB8xgABMMAPgAAAHicY2Bm42OcwMDKwMLSw2LMwMDQBqGZihmiwHycoKCyqJjB4YPDh4NsDP+BfNb3DIuAFCOSEgUGRgAKDgt4AAB4nGNgYGBmgGAZBkYGEAgB8hjBfBYGCyDNxcDBwMTA9MHhQ9SHrA8H//9nYACyQyFs/sP86/kX8HtB9UIBIxsDXICRCUgwMaACRoZhDwA3fxKSAAAAAAHyAHABJQB/AIEAdAFGAOsBIwC/ALgAxACGAGYAugBNACcA/wCIeJxdUbtOW0EQ3Q0PA4HE2CA52hSzmZDGe6EFCcTVjWJkO4XlCGk3cpGLcQEfQIFEDdqvGaChpEibBiEXSHxCPiESM2uIojQ7O7NzzpkzS8qRqn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fgF0r/zJQB4nG2JUQuCQBCEd07TTg36fb2IyBaLd3vWaUh/vmSJnvpgmG8YcmS8X3Shf3R7QA4OBUocUKHGER5NNbOOEvwc1txnuWkTRb/aPjimJ5vXabI+3VfOiyS15UWvyezM2xiGOPyuMohOH8O8JiO4Af+FsAGNAEuwCFBYsQEBjlmxRgYrWCGwEFlLsBRSWCGwgFkdsAYrXFhZsBQrAAA=) format('woff');
}

@font-face {
  font-family: octicons-anchor;
  src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQHngNFaG10eAAAAvwAAAAQAAAAEAwAACJsb2NhAAADDAAAAAoAAAAKALIAVG1heHAAAAMYAAAAHwAAACABEAB2bmFtZQAAAzgAAALBAAAFu3I9x/Nwb3N0AAAF/AAAAB0AAAAvaoFvbwAAAAEAAAAAzBdyYwAAAADP2IQvAAAAAM/bz7t4nGNgZGFgnMDAysDB1Ml0hoGBoR9CM75mMGLkYGBgYmBlZsAKAtJcUxgcPsR8iGF2+O/AEMPsznAYKMwIkgMA5REMOXicY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+h5j//yEk/3KoSgZGNgYYk4GRCUgwMaACRoZhDwCs7QgGAAAAIgKIAAAAAf//AAJ4nHWMMQrCQBBF/0zWrCCIKUQsTDCL2EXMohYGSSmorScInsRGL2DOYJe0Ntp7BK+gJ1BxF1stZvjz/v8DRghQzEc4kIgKwiAppcA9LtzKLSkdNhKFY3HF4lK69ExKslx7Xa+vPRVS43G98vG1DnkDMIBUgFN0MDXflU8tbaZOUk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1xHzTXRqgKzek/mb7nB8RZTCDhGEX3kK/8Q75AmUM/eLkfA+0Hi908Kx4eNsMgudg5GLdRD7a84npi+YxNr5i5KIbW5izXas7cHXIMAau1OueZhfj+cOcP3P8MNIWLyYOBuxL6DRylJ4cAAAB4nGNgYoAALjDJyIAOWMCiTIxMLDmZedkABtIBygAAAA==) format('woff');
}

.markdown-body {
  font-family: sans-serif;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  color: #333333;
  overflow: hidden;
  font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  word-wrap: break-word;
}

.markdown-body a {
  background: transparent;
}

.markdown-body a:active,
.markdown-body a:hover {
  outline: 0;
}

.markdown-body b,
.markdown-body strong {
  font-weight: bold;
}

.markdown-body mark {
  background: #ff0;
  color: #000;
  font-style: italic;
  font-weight: bold;
}

.markdown-body sub,
.markdown-body sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}
.markdown-body sup {
  top: -0.5em;
}
.markdown-body sub {
  bottom: -0.25em;
}

.markdown-body h1 {
  font-size: 2em;
  margin: 0.67em 0;
}

.markdown-body img {
  border: 0;
}

.markdown-body hr {
  -moz-box-sizing: content-box;
  box-sizing: content-box;
  height: 0;
}

.markdown-body pre {
  overflow: auto;
}

.markdown-body code,
.markdown-body kbd,
.markdown-body pre,
.markdown-body samp {
  font-family: monospace, monospace;
  font-size: 1em;
}

.markdown-body input {
  color: inherit;
  font: inherit;
  margin: 0;
}

.markdown-body html input[disabled] {
  cursor: default;
}

.markdown-body input {
  line-height: normal;
}

.markdown-body input[type="checkbox"] {
  box-sizing: border-box;
  padding: 0;
}

.markdown-body table {
  border-collapse: collapse;
  border-spacing: 0;
}

.markdown-body td,
.markdown-body th {
  padding: 0;
}

.markdown-body .codehilitetable {
  border: 0;
  border-spacing: 0;
}

.markdown-body .codehilitetable tr {
  border: 0;
}

.markdown-body .codehilitetable pre,
.markdown-body .codehilitetable div.codehilite {
  margin: 0;
}

.markdown-body .linenos,
.markdown-body .code,
.markdown-body .codehilitetable td {
  border: 0;
  padding: 0;
}

.markdown-body td:not(.linenos) .linenodiv {
  padding: 0 !important;
}

.markdown-body .code {
  width: 100%;
}

.markdown-body .linenos div pre,
.markdown-body .linenodiv pre,
.markdown-body .linenodiv {
  border: 0;
  -webkit-border-radius: 0;
  -moz-border-radius: 0;
  border-radius: 0;
  -webkit-border-top-left-radius: 3px;
  -webkit-border-bottom-left-radius: 3px;
  -moz-border-radius-topleft: 3px;
  -moz-border-radius-bottomleft: 3px;
  border-top-left-radius: 3px;
  border-bottom-left-radius: 3px;
}

.markdown-body .code div pre,
.markdown-body .code div {
  border: 0;
  -webkit-border-radius: 0;
  -moz-border-radius: 0;
  border-radius: 0;
  -webkit-border-top-right-radius: 3px;
  -webkit-border-bottom-right-radius: 3px;
  -moz-border-radius-topright: 3px;
  -moz-border-radius-bottomright: 3px;
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
}

.markdown-body * {
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.markdown-body input {
  font: 13px Helvetica, arial, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  line-height: 1.4;
}

.markdown-body a {
  color: #4183c4;
  text-decoration: none;
}

.markdown-body a:hover,
.markdown-body a:focus,
.markdown-body a:active {
  text-decoration: underline;
}

.markdown-body hr {
  height: 0;
  margin: 15px 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #ddd;
}

.markdown-body hr:before,
.markdown-body hr:after {
  display: table;
  content: " ";
}

.markdown-body hr:after {
  clear: both;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 15px;
  margin-bottom: 15px;
  line-height: 1.1;
}

.markdown-body h1 {
  font-size: 30px;
}

.markdown-body h2 {
  font-size: 21px;
}

.markdown-body h3 {
  font-size: 16px;
}

.markdown-body h4 {
  font-size: 14px;
}

.markdown-body h5 {
  font-size: 12px;
}

.markdown-body h6 {
  font-size: 11px;
}

.markdown-body blockquote {
  margin: 0;
}

.markdown-body ul,
.markdown-body ol {
  padding: 0;
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body ol ol,
.markdown-body ul ol {
  list-style-type: lower-roman;
}

.markdown-body ul ul ol,
.markdown-body ul ol ol,
.markdown-body ol ul ol,
.markdown-body ol ol ol {
  list-style-type: lower-alpha;
}

.markdown-body dd {
  margin-left: 0;
}

.markdown-body code,
.markdown-body pre,
.markdown-body samp {
  font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
  font-size: 12px;
}

.markdown-body pre {
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body kbd {
  background-color: #e7e7e7;
  background-image: -moz-linear-gradient(#fefefe, #e7e7e7);
  background-image: -webkit-linear-gradient(#fefefe, #e7e7e7);
  background-image: linear-gradient(#fefefe, #e7e7e7);
  background-repeat: repeat-x;
  border-radius: 2px;
  border: 1px solid #cfcfcf;
  color: #000;
  padding: 3px 5px;
  line-height: 10px;
  font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  display: inline-block;
}

.markdown-body>*:first-child {
  margin-top: 0 !important;
}

.markdown-body>*:last-child {
  margin-bottom: 0 !important;
}

.markdown-body .headeranchor-link {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  display: block;
  padding-right: 6px;
  padding-left: 30px;
  margin-left: -30px;
}

.markdown-body .headeranchor-link:focus {
  outline: none;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  position: relative;
  margin-top: 1em;
  margin-bottom: 16px;
  font-weight: bold;
  line-height: 1.4;
}

.markdown-body h1 .headeranchor,
.markdown-body h2 .headeranchor,
.markdown-body h3 .headeranchor,
.markdown-body h4 .headeranchor,
.markdown-body h5 .headeranchor,
.markdown-body h6 .headeranchor {
  display: none;
  color: #000;
  vertical-align: middle;
}

.markdown-body h1:hover .headeranchor-link,
.markdown-body h2:hover .headeranchor-link,
.markdown-body h3:hover .headeranchor-link,
.markdown-body h4:hover .headeranchor-link,
.markdown-body h5:hover .headeranchor-link,
.markdown-body h6:hover .headeranchor-link {
  height: 1em;
  padding-left: 8px;
  margin-left: -30px;
  line-height: 1;
  text-decoration: none;
}

.markdown-body h1:hover .headeranchor-link .headeranchor,
.markdown-body h2:hover .headeranchor-link .headeranchor,
.markdown-body h3:hover .headeranchor-link .headeranchor,
.markdown-body h4:hover .headeranchor-link .headeranchor,
.markdown-body h5:hover .headeranchor-link .headeranchor,
.markdown-body h6:hover .headeranchor-link .headeranchor {
  display: inline-block;
}

.markdown-body h1 {
  padding-bottom: 0.3em;
  font-size: 2.25em;
  line-height: 1.2;
  border-bottom: 1px solid #eee;
}

.markdown-body h2 {
  padding-bottom: 0.3em;
  font-size: 1.75em;
  line-height: 1.225;
  border-bottom: 1px solid #eee;
}

.markdown-body h3 {
  font-size: 1.5em;
  line-height: 1.43;
}

.markdown-body h4 {
  font-size: 1.25em;
}

.markdown-body h5 {
  font-size: 1em;
}

.markdown-body h6 {
  font-size: 1em;
  color: #777;
}

.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre,
.markdown-body .admonition {
  margin-top: 0;
  margin-bottom: 16px;
}

.markdown-body hr {
  height: 4px;
  padding: 0;
  margin: 16px 0;
  background-color: #e7e7e7;
  border: 0 none;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 2em;
}

.markdown-body ul ul,
.markdown-body ul ol,
.markdown-body ol ol,
.markdown-body ol ul {
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body li>p {
  margin-top: 16px;
}

.markdown-body dl {
  padding: 0;
}

.markdown-body dl dt {
  padding: 0;
  margin-top: 16px;
  font-size: 1em;
  font-style: italic;
  font-weight: bold;
}

.markdown-body dl dd {
  padding: 0 16px;
  margin-bottom: 16px;
}

.markdown-body blockquote {
  padding: 0 15px;
  color: #777;
  border-left: 4px solid #ddd;
}

.markdown-body blockquote>:first-child {
  margin-top: 0;
}

.markdown-body blockquote>:last-child {
  margin-bottom: 0;
}

.markdown-body table {
  display: block;
  width: 100%;
  overflow: auto;
  word-break: normal;
  word-break: keep-all;
}

.markdown-body table th {
  font-weight: bold;
}

.markdown-body table th,
.markdown-body table td {
  padding: 6px 13px;
  border: 1px solid #ddd;
}

.markdown-body table tr {
  background-color: #fff;
  border-top: 1px solid #ccc;
}

.markdown-body table tr:nth-child(2n) {
  background-color: #f8f8f8;
}

.markdown-body img {
  max-width: 100%;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.markdown-body code,
.markdown-body samp {
  padding: 0;
  padding-top: 0.2em;
  padding-bottom: 0.2em;
  margin: 0;
  font-size: 85%;
  background-color: rgba(0,0,0,0.04);
  border-radius: 3px;
}

.markdown-body code:before,
.markdown-body code:after {
  letter-spacing: -0.2em;
  content: "\00a0";
}

.markdown-body pre>code {
  padding: 0;
  margin: 0;
  font-size: 100%;
  word-break: normal;
  white-space: pre;
  background: transparent;
  border: 0;
}

.markdown-body .codehilite {
  margin-bottom: 16px;
}

.markdown-body .codehilite pre,
.markdown-body pre {
  padding: 16px;
  overflow: auto;
  font-size: 85%;
  line-height: 1.45;
  background-color: #f7f7f7;
  border-radius: 3px;
}

.markdown-body .codehilite pre {
  margin-bottom: 0;
  word-break: normal;
}

.markdown-body pre {
  word-wrap: normal;
}

.markdown-body pre code {
  display: inline;
  max-width: initial;
  padding: 0;
  margin: 0;
  overflow: initial;
  line-height: inherit;
  word-wrap: normal;
  background-color: transparent;
  border: 0;
}

.markdown-body pre code:before,
.markdown-body pre code:after {
  content: normal;
}

/* Admonition */
.markdown-body .admonition {
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  position: relative;
  border-radius: 3px;
  border: 1px solid #e0e0e0;
  border-left: 6px solid #333;
  padding: 10px 10px 10px 30px;
}

.markdown-body .admonition table {
  color: #333;
}

.markdown-body .admonition p {
  padding: 0;
}

.markdown-body .admonition-title {
  font-weight: bold;
  margin: 0;
}

.markdown-body .admonition>.admonition-title {
  color: #333;
}

.markdown-body .attention>.admonition-title {
  color: #a6d796;
}

.markdown-body .caution>.admonition-title {
  color: #d7a796;
}

.markdown-body .hint>.admonition-title {
  color: #96c6d7;
}

.markdown-body .danger>.admonition-title {
  color: #c25f77;
}

.markdown-body .question>.admonition-title {
  color: #96a6d7;
}

.markdown-body .note>.admonition-title {
  color: #d7c896;
}

.markdown-body .admonition:before,
.markdown-body .attention:before,
.markdown-body .caution:before,
.markdown-body .hint:before,
.markdown-body .danger:before,
.markdown-body .question:before,
.markdown-body .note:before {
  font: normal normal 16px fontawesome-mini;
  -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  line-height: 1.5;
  color: #333;
  position: absolute;
  left: 0;
  top: 0;
  padding-top: 10px;
  padding-left: 10px;
}

.markdown-body .admonition:before {
  content: "\f056\00a0";
  color: 333;
}

.markdown-body .attention:before {
  content: "\f058\00a0";
  color: #a6d796;
}

.markdown-body .caution:before {
  content: "\f06a\00a0";
  color: #d7a796;
}

.markdown-body .hint:before {
  content: "\f05a\00a0";
  color: #96c6d7;
}

.markdown-body .danger:before {
  content: "\f057\00a0";
  color: #c25f77;
}

.markdown-body .question:before {
  content: "\f059\00a0";
  color: #96a6d7;
}

.markdown-body .note:before {
  content: "\f040\00a0";
  color: #d7c896;
}

.markdown-body .admonition::after {
  content: normal;
}

.markdown-body .attention {
  border-left: 6px solid #a6d796;
}

.markdown-body .caution {
  border-left: 6px solid #d7a796;
}

.markdown-body .hint {
  border-left: 6px solid #96c6d7;
}

.markdown-body .danger {
  border-left: 6px solid #c25f77;
}

.markdown-body .question {
  border-left: 6px solid #96a6d7;
}

.markdown-body .note {
  border-left: 6px solid #d7c896;
}

.markdown-body .admonition>*:first-child {
  margin-top: 0 !important;
}

.markdown-body .admonition>*:last-child {
  margin-bottom: 0 !important;
}

/* progress bar*/
.markdown-body .progress {
  display: block;
  width: 300px;
  margin: 10px 0;
  height: 24px;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  background-color: #ededed;
  position: relative;
  box-shadow: inset -1px 1px 3px rgba(0, 0, 0, .1);
}

.markdown-body .progress-label {
  position: absolute;
  text-align: center;
  font-weight: bold;
  width: 100%; margin: 0;
  line-height: 24px;
  color: #333;
  text-shadow: 1px 1px 0 #fefefe, -1px -1px 0 #fefefe, -1px 1px 0 #fefefe, 1px -1px 0 #fefefe, 0 1px 0 #fefefe, 0 -1px 0 #fefefe, 1px 0 0 #fefefe, -1px 0 0 #fefefe, 1px 1px 2px #000;
  -webkit-font-smoothing: antialiased !important;
  white-space: nowrap;
  overflow: hidden;
}

.markdown-body .progress-bar {
  height: 24px;
  float: left;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  background-color: #96c6d7;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 -1px 0 rgba(0, 0, 0, .1);
  background-size: 30px 30px;
  background-image: -webkit-linear-gradient(
    135deg, rgba(255, 255, 255, .4) 27%,
    transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%,
    transparent 77%, transparent
  );
  background-image: -moz-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: -ms-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: -o-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
}

.markdown-body .progress-100plus .progress-bar {
  background-color: #a6d796;
}

.markdown-body .progress-80plus .progress-bar {
  background-color: #c6d796;
}

.markdown-body .progress-60plus .progress-bar {
  background-color: #d7c896;
}

.markdown-body .progress-40plus .progress-bar {
  background-color: #d7a796;
}

.markdown-body .progress-20plus .progress-bar {
  background-color: #d796a6;
}

.markdown-body .progress-0plus .progress-bar {
  background-color: #c25f77;
}

.markdown-body .candystripe-animate .progress-bar{
  -webkit-animation: animate-stripes 3s linear infinite;
  -moz-animation: animate-stripes 3s linear infinite;
  animation: animate-stripes 3s linear infinite;
}

@-webkit-keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

@-moz-keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

@keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

.markdown-body .gloss .progress-bar {
  box-shadow:
    inset 0 4px 12px rgba(255, 255, 255, .7),
    inset 0 -12px 0 rgba(0, 0, 0, .05);
}

/* Multimarkdown Critic Blocks */
.markdown-body .critic_mark {
  background: #ff0;
}

.markdown-body .critic_delete {
  color: #c82829;
  text-decoration: line-through;
}

.markdown-body .critic_insert {
  color: #718c00 ;
  text-decoration: underline;
}

.markdown-body .critic_comment {
  color: #8e908c;
  font-style: italic;
}

.markdown-body .headeranchor {
  font: normal normal 16px octicons-anchor;
  line-height: 1;
  display: inline-block;
  text-decoration: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.headeranchor:before {
  content: '\f05c';
}

.markdown-body .task-list-item {
  list-style-type: none;
}

.markdown-body .task-list-item+.task-list-item {
  margin-top: 3px;
}

.markdown-body .task-list-item input {
  margin: 0 4px 0.25em -20px;
  vertical-align: middle;
}

/* Media */
@media only screen and (min-width: 480px) {
  .markdown-body {
    font-size:14px;
  }
}

@media only screen and (min-width: 768px) {
  .markdown-body {
    font-size:16px;
  }
}

@media print {
  .markdown-body * {
    background: transparent !important;
    color: black !important;
    filter:none !important;
    -ms-filter: none !important;
  }

  .markdown-body {
    font-size:12pt;
    max-width:100%;
    outline:none;
    border: 0;
  }

  .markdown-body a,
  .markdown-body a:visited {
    text-decoration: underline;
  }

  .markdown-body .headeranchor-link {
    display: none;
  }

  .markdown-body a[href]:after {
    content: " (" attr(href) ")";
  }

  .markdown-body abbr[title]:after {
    content: " (" attr(title) ")";
  }

  .markdown-body .ir a:after,
  .markdown-body a[href^="javascript:"]:after,
  .markdown-body a[href^="#"]:after {
    content: "";
  }

  .markdown-body pre {
    white-space: pre;
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  .markdown-body pre,
  .markdown-body blockquote {
    border: 1px solid #999;
    padding-right: 1em;
    page-break-inside: avoid;
  }

  .markdown-body .progress,
  .markdown-body .progress-bar {
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
  }

  .markdown-body .progress {
    border: 1px solid #ddd;
  }

  .markdown-body .progress-bar {
    height: 22px;
    border-right: 1px solid #ddd;
  }

  .markdown-body tr,
  .markdown-body img {
    page-break-inside: avoid;
  }

  .markdown-body img {
    max-width: 100% !important;
  }

  .markdown-body p,
  .markdown-body h2,
  .markdown-body h3 {
    orphans: 3;
    widows: 3;
  }

  .markdown-body h2,
  .markdown-body h3 {
    page-break-after: avoid;
  }
}
</style><title>AJAX</title></head><body><article class="markdown-body"><div class="toc">
<ul>
<li><a href="#ajax">Ajax</a><ul>
<li><a href="#ajax_1">了解AJAX</a></li>
<li><a href="#ajax_2">AJAX请求步骤</a></li>
<li><a href="#xmlhttprequest">XMLHttpRequest对象属性方法</a><ul>
<li><a href="#xmlhttprequest_1">XMLHttpRequest的兼容性</a></li>
</ul>
</li>
<li><a href="#json">JSON数据的应用</a></li>
<li><a href="#promise">Promise</a><ul>
<li><a href="#promise_1">Promise 的三种状态</a></li>
<li><a href="#_1">方法</a><ul>
<li><a href="#_2">静态方法</a></li>
<li><a href="#_3">原型方法</a></li>
</ul>
</li>
<li><a href="#_4">使用</a></li>
<li><a href="#_5">应用</a></li>
</ul>
</li>
<li><a href="#ajax_3">ajax跨域解决方案</a><ul>
<li><a href="#jsonp">JSONP</a><ul>
<li><a href="#jsonp_1">jsonp请求原理</a></li>
</ul>
</li>
<li><a href="#cors">CORS</a></li>
<li><a href="#_6">服务器代理</a></li>
</ul>
</li>
<li><a href="#api">API</a></li>
</ul>
</li>
</ul>
</div>
<h1 id="ajax"><a name="user-content-ajax" href="#ajax" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Ajax</h1>
<h2 id="ajax_1"><a name="user-content-ajax_1" href="#ajax_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>了解AJAX</h2>
<ul>
<li>AJAX: Asynchronous Javascript And Xml，Ajax 技术的核心是XMLHttpRequest对象（简称XHR），这是由微软首先引入的一个特性，其他浏览器提供商后来都提供了相同的实现</li>
</ul>
<p>*Ajax起源：<br />
最早出现在google的下拉提示</p>
<ul>
<li>
<p>ajax优点</p>
<ul>
<li>增加速度：减轻服务器的负担,按需加载数据,最大程度的减少冗余请求</li>
<li>改善的用户体验：局部刷新页面,减少用户等待时间,带来更好的用户体验</li>
<li>页面和数据分离：前后端分离，操作更灵活，后期维护更方便</li>
</ul>
</li>
<li>
<p>同步与异步？</p>
<ul>
<li>同步：按步骤顺序执行，前面的代码执行完后，后面的代码才会执行<blockquote>
<p>做完前一件事情, 才能下一件事情（排队）</p>
</blockquote>
</li>
<li>异步：与其他操作同时执行，也叫并发（图片加载，浏览器解析代码）</li>
</ul>
</li>
<li>
<p>后端语言和服务器配置</p>
<ul>
<li>NodeJS + MongoDB</li>
<li>Java + jdk + tomcat + mySQL</li>
<li>php + Apache + mySQL</li>
<li>.net + IIS + SQL Server</li>
</ul>
</li>
</ul>
<h2 id="ajax_2"><a name="user-content-ajax_2" href="#ajax_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>AJAX请求步骤</h2>
<ol>
<li>
<p>创建请求对象,返回一个异步请求对象<br />
<code>var request = new XMLHttpRequest();</code></p>
</li>
<li>
<p>处理服务器返回数据<br />
<pre><code>request.onreadystatechange = function(){
    if(request.readyState == 4) {
        alert(request.responseText);
    }
}
</code></pre></p>
</li>
<li>
<p>设置请求参数，建立与服务器连接<br />
<code>request.open("get", "http://localhost/ajax/ajaxtest", true);</code></p>
</li>
<li>
<p>向服务器发送请求<br />
<code>request.send(null);</code></p>
</li>
</ol>
<h2 id="xmlhttprequest"><a name="user-content-xmlhttprequest" href="#xmlhttprequest" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>XMLHttpRequest对象属性方法</h2>
<ul>
<li>
<p>open(type,url,async): 建立与服务器的连接</p>
<ul>
<li>type：请求的类型 （&rsquo;get&rsquo;, &lsquo;post&rsquo;）</li>
<li>
<p>url：数据请求的地址（只能请求同域URL），一般有后端开发人员提供</p>
<ul>
<li>页面请求地址，API地址两者一定要&lt;同域&gt;</li>
<li>同域：协议，域名，端口三者一致（同源策略）</li>
</ul>
</li>
<li>
<p>async：是否异步发送请求（true,false）</p>
</li>
</ul>
</li>
<li>
<p>send(data): 向服务器发送请求</p>
<ul>
<li>data：可选参数，post请求时才生效，表示发请求时传送的数据字符串。（在某些浏览器中，如果不需要通过请求主体发送数据，则必须传入null）<br />
<pre><code>    xhr.send('size=20&amp;type=music');
</code></pre><blockquote>
<p>PS:get请求的数据写在api地址后</p>
</blockquote>
</li>
</ul>
</li>
<li>setRequestHeader(key,val)：设置请求头<ul>
<li>设置请求头必须在open方法调用后设置</li>
</ul>
</li>
</ul>
<blockquote>
<p>**在请求收到服务器的响应后，响应的数据会自动填充XHR 对象的属性，相关的属性简介如下：</p>
</blockquote>
<ul>
<li>readyState<ul>
<li>0 － （未初始化）尚未调用open()方法。</li>
<li>1 － （启动）已经调用open()方法，但尚未调用send()方法。</li>
<li>2 － （发送）send()方法执行完成，但尚未接收到响应。</li>
<li>3 － （接收）已经接收到部分响应数据。</li>
<li>4 － （完成）响应内容解析完成，可以在客户端调用了</li>
</ul>
</li>
</ul>
<blockquote>
<p>只要readyState 属性的值由一个值变成另一个值，都会触发一次readystatechange 事件。必须在调用open()之前指定onreadystatechange事件处理程序才能确保跨浏览器兼容性。</p>
</blockquote>
<ul>
<li>responseText：保存服务器返回的数据（从服务器返回的数据是“字符串”）。</li>
<li>status：响应的HTTP 状态。<ul>
<li>200（OK）：服务器成功返回了页面</li>
<li>304（Not Modified）：数据与服务器相同，不需要重服务器请求（直接使用缓存的数据）</li>
<li>400（Bad Request）：语法错误导致服务器不识别</li>
<li>401（Unauthorized）：请求需要用户认证</li>
<li>404（Not found）：请求地址不存在</li>
<li>500（Internal Server Error）：服务器出错或无响应</li>
<li>503（ServiceUnavailable）：由于服务器过载或维护导致无法完成请求</li>
</ul>
</li>
<li>statusText: HTTP状态码的说明</li>
</ul>
<h3 id="xmlhttprequest_1"><a name="user-content-xmlhttprequest_1" href="#xmlhttprequest_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>XMLHttpRequest的兼容性</h3>
<pre><code>var req = null;
try{
    req = new XMLHttpRequest();
}catch(err){
    // ie低版本浏览有多种异步请求的实现
    try{
        req = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);
    }catch(err){
        try{
            req = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
        }catch(err){
            alert('你的浏览器太low了，这个世界不适合你');
        }
    }

}

</code></pre>

<h2 id="json"><a name="user-content-json" href="#json" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>JSON数据的应用</h2>
<ul>
<li>
<p>xml<br />
<pre><code>&lt;person&gt;
    &lt;id&gt;4564523626256562&lt;/id&gt;
    &lt;name&gt;张三&lt;/name&gt;
&lt;/person&gt;
</code></pre></p>
</li>
<li>
<p>json数据(json字符串)<br />
<pre><code>{&quot;id&quot; : 21465461461461, &quot;name&quot;: &quot;张三&quot;},[{&quot;id&quot; : 21465461461461, &quot;name&quot;: &quot;张三&quot;}]
</code></pre></p>
<ul>
<li>json数据格式要求：<ul>
<li>属性名必须加双引号</li>
<li>字符串必须加双引号</li>
<li>不能有注释</li>
<li>最后不能有多余逗号</li>
</ul>
</li>
</ul>
</li>
<li>
<p>eval方法的使用<br />
<code>eval("("+json字符串+")");</code> <br />
它的作用是，将一个普通的json格式的字符串，转换成Json格式的对象<br />
举例：<br />
<pre><code>var list = eval(&quot;(&quot;+request.responseText+&quot;)&quot;);
</code></pre></p>
</li>
<li>
<p>JSON对象(ES5)</p>
<ul>
<li>JSON.parse(); //把JSON字符串转成JSON对象(js对象/数组)</li>
<li>JSON.stringify(); //把JSON对象转成JSON字符串</li>
</ul>
</li>
<li>
<p>加载json文件<br />
前后端分离开发时模拟数据</p>
</li>
</ul>
<h2 id="promise"><a name="user-content-promise" href="#promise" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Promise</h2>
<p>Promise是一个构造函数，所谓的Promise对象，就是通过new Promise()示例化得到的对象，用来传递异步操作的消息。它代表了某个未来才会知道结果的事件（通常是一个异步操作），并且这个事件提供统一的 API，可供进一步处理。</p>
<h3 id="promise_1"><a name="user-content-promise_1" href="#promise_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Promise 的三种状态</h3>
<ul>
<li>Pending（未完成）可以理解为Promise对象实例创建时候的初始状态</li>
<li>Resolved（成功） 可以理解为成功的状态</li>
<li>Rejected（失败） 可以理解为失败的状态</li>
</ul>
<h3 id="_1"><a name="user-content-_1" href="#_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>方法</h3>
<h4 id="_2"><a name="user-content-_2" href="#_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>静态方法</h4>
<ul>
<li>Promise.resolve()<br />
将现有对象转为Promise对象<br />
<pre><code>var p = Promise.resolve('foo');

// 等价于
var p = new Promise(resolve =&gt; resolve('foo'));
</code></pre></li>
<li>Promise.reject()<br />
返回一个新的 Promise 实例，该实例的状态为rejected</li>
<li>Promise.all(p1,p2,p3&hellip;) <br />
将多个Promise实例，包装成一个新的Promise实例<ul>
<li>所有参数中的promise状态都为resolved是，新的promise状态才为resolved</li>
<li>只要p1、p2、p3..之中有一个被rejected，新的promise的状态就变成rejected</li>
</ul>
</li>
<li>Promise.race() // 竞速，完成一个即可</li>
</ul>
<h4 id="_3"><a name="user-content-_3" href="#_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>原型方法</h4>
<ul>
<li>Promise.prototype.then(successFn[,failFn])<br />
Promise实例生成以后，可以用then方法分别指定Resolved状态和Rejected状态的回调函数。并根据Promise对象的状态来确定执行的操作:<ul>
<li>resolved时执行第一个函数successFn</li>
<li>rejected时执行第二个函数failFn。</li>
</ul>
</li>
<li>Promise.prototype.catch(failFn)</li>
</ul>
<h3 id="_4"><a name="user-content-_4" href="#_4" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>使用</h3>
<p><pre><code>var p = new Promise(function(resolve, reject){
    //ajax请求
    ajax({
        url:'xxx.php',
        success:function(data){
            resolve(data)
        },
        fail:function(){
            reject('请求失败')
        }
    });
});

//指定Resolved状态和Rejected状态的回调函数
//一般用于处理数据
p.then(function(res){
    //这里得到resolve传过来的数据
},function(err){
    //这里得到reject传过来的数据
})
</code></pre><br />
Promise的构造函数接收一个回调函数作为参数，并且传入两个参数：resolve，reject，分别表示异步操作执行成功和失败后的回调函数</p>
<ul>
<li>调用resolve方法将Promise对象的状态从「未完成」变为「成功」（从 pending 变为 resolved）；</li>
<li>调用reject方法将Promise对象的状态从「未完成」变为「失败」（从 pending 变为 rejected）</li>
<li>如果调用resolve函数和reject函数时带有参数，那么它们的参数会被传递给回调函数</li>
</ul>
<blockquote>
<p>有了Promise对象，就可以将异步操作以同步操作的流程表达出来，避免了层层嵌套的回调函数</p>
</blockquote>
<h3 id="_5"><a name="user-content-_5" href="#_5" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>应用</h3>
<ul>
<li>加载图片，获取图片信息（宽高）<br />
<pre><code>var preloadImage = function (path) {
  return new Promise(function (resolve, reject) {
    var image = new Image();
    image.onload  = ()=&gt;{
        resolve(image);
    }
    image.onerror = reject;
    image.src = path;
  });
};

//使用
preloadImage('http://image.baidu.com/xxx.jpg').then((img)=&gt;{
    document.body.appendChild(img);
    console.log(img.offsetWidth,img.offsetHeight);
})
</code></pre></li>
<li>ajax请求数据依赖</li>
</ul>
<h2 id="ajax_3"><a name="user-content-ajax_3" href="#ajax_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>ajax跨域解决方案</h2>
<h3 id="jsonp"><a name="user-content-jsonp" href="#jsonp" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>JSONP</h3>
<p>JSONP 是JSON with padding（填充式JSON 或参数式JSON）的简写。<br />
JSONP是一种可以绕过浏览器的安全限制，从不同的域请求数据的方法。使用JSONP需要服务器端提供必要的支持。<br />
<pre><code>callback({ &quot;name&quot;: &quot;Nicholas&quot; });//此代码在服务器生成
</code></pre></p>
<blockquote>
<p>JSONP 由两部分组成：回调函数和数据。回调函数是当响应到来时应该在页面中调用的函数</p>
</blockquote>
<h4 id="jsonp_1"><a name="user-content-jsonp_1" href="#jsonp_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>jsonp请求原理</h4>
<ul>
<li>
<p>JSONP的原理是通过script标签发起一个GET请求来取代XHR请求。</p>
<ul>
<li>JSONP生成一个script标签并插到DOM中，</li>
<li>然后浏览器会接管并向src属性所指向的地址发送请求。</li>
<li>从服务器端返回一段js代码，这段代码就是一个函数的执行（执行时把数据作为参数传入，函数为本地预定义的函数）,这个我们就间接地得到了服务器传出的数据。</li>
</ul>
</li>
<li>
<p>步骤如下：</p>
<ol>
<li>
<p>预定义全局函数getData<br />
<pre><code>function getData(data){
    console.log(data);
}
</code></pre></p>
<blockquote>
<p>PS:预定义函数必须为全局函数</p>
</blockquote>
</li>
<li>
<p>生成script标签，请求服务器地址,并附带函数名<br />
<pre><code>&lt;script src=&quot;http://localhost:3000/getJSONP?callback=getData&quot;&gt;&lt; /script&gt;
</code></pre></p>
</li>
<li>服务器返回js文件（js文件里面包含我们预先定义的函数执行）<br />
请求成功后，得到的js文件的代码为<br />
<pre><code>getData({name: '王大锤',age: 30,sex: '男',married:false})
</code></pre><br />
当这个函数成功调用时，就可以执行预定义函数里的代码（处理返回的数据）</li>
</ol>
</li>
</ul>
<blockquote>
<p>jsonp请求不是ajax请求，是利用script标签能加载其他域名的js文件的原理，来实现跨域数据的请求</p>
</blockquote>
<h3 id="cors"><a name="user-content-cors" href="#cors" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>CORS</h3>
<p>CORS是一个W3C标准，全称是&rdquo;跨域资源共享&rdquo;（Cross-origin resource sharing），它允许浏览器向跨源服务器发出XMLHttpRequest请求，从而克服了AJAX只能同源使用的限制</p>
<blockquote>
<p>CORS需要浏览器和服务器同时支持。目前，所有浏览器都支持该功能，IE浏览器不能低于IE10。</p>
</blockquote>
<ul>
<li>Access-Control-Allow-Origin<br />
该字段是必须的。它的值要么是请求时Origin字段的值，要么是一个*，表示接受任意域名的请求</li>
</ul>
<h3 id="_6"><a name="user-content-_6" href="#_6" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>服务器代理</h3>
<h2 id="api"><a name="user-content-api" href="#api" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>API</h2>
<ul>
<li>
<p>利用jsonp实现百度搜索关键字建议<br />
<code>https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?json=1&amp;cb=getData&amp;wd=html5</code></p>
</li>
<li>
<p>利用CORS加载天气<br />
    接口地址：<code>http://wthrcdn.etouch.cn/weather_mini?city=北京</code><br />
    接口描述：通过城市名字获得天气数据，json数据</p>
</li>
<li>
<p>服务器API</p>
<ul>
<li>
<p>向服务器请求数据：<br />
接口地址：/ajax/ajaxtest.php<br />
接口描述：返回一段字符串，无特殊功能</p>
</li>
<li>
<p>判断用户名是否已被注册<br />
接口地址：/ajax/checkname?regname=xiejinrong<br />
接口描述：该地址验证所提交的用户名是否存在，如果已存在，返回字符串no，不存在返回yes<br />
参数说明：regname:注册用户名，必填</p>
<blockquote>
<p>已经存在的名字：&rsquo;张三&rsquo;,&rsquo;李四&rsquo;,&rsquo;王尼玛&rsquo;,&rsquo;奥巴马&rsquo;</p>
</blockquote>
</li>
<li>
<p>微博消息获取：<br />
接口地址：/ajax/weibo.php<br />
接口描述：返回包含多条微博记录的json数据</p>
</li>
<li>
<p>分页获取数据：<br />
接口地址：/ajax/football.php  <br />
接口描述：该地址请求多条微博信息，分页获取，pageNo指定获取第几页的数据<br />
参数说明：</p>
<ul>
<li>pageNo:当前分页，默认1</li>
<li>qty:每页显示数量，默认10</li>
</ul>
</li>
<li>
<p>聊天室：<br />
获取本机ip地址：ip地址/ajax/getip.php<br />
获取信息：/ajax/chat.php?type=query<br />
发送信息：/ajax/chat.php?type=send&amp;sender=xiejinrong&amp;msg=hello</p>
</li>
<li>
<p>利用jsonp获取远程数据<br />
接口地址：/ajax/jsonp.php<br />
接口描述：jsonp跨域解决方案</p>
</li>
<li>
<p>获取CORS获取远程数据<br />
接口地址：/ajax/cors.php<br />
接口描述：CORS跨域解决方案</p>
</li>
</ul>
</li>
</ul>
<hr />
<p><strong>[作业]</strong></p>
<ol>
<li>封装ajax函数，要求如下：<ul>
<li>简化ajax请求操作</li>
<li>解决兼容性问题</li>
<li>支持跨域JSONP请求</li>
</ul>
</li>
<li>aja请求json数据实现实现城市列表的展示<ul>
<li>显示热门城市</li>
<li>支持字母索引</li>
<li>点击城市显示相应天气信息</li>
</ul>
</li>
</ol>
<p><strong>[扩展]</strong></p>
<ul>
<li>全国地市三级联动效果</li>
</ul></article></body></html>